/*
 * Bitmap.h
 *
 *  Created on: Oct 5, 2012
 *      Author: burek
 */

#ifndef BITMAP_H_
#define BITMAP_H_

#include "integers.h"

#define R_COMP(x) (x ^ 0xFF)
#define G_COMP(x) ((x >> 8) ^ 0xFF)
#define B_COMP(x) ((x >> 16) ^ 0xFF)
#define A_COMP(x) ((x >> 24) ^ 0xFF)

//#define FROM_RGB(r,g,b) (r | (g << 8) | (b << 16))
//#define FROM_RGBA(r,g,b,a) (r | (g << 8) | (b << 16) | (a << 24))

#define FROM_RGB(r,g,b) ((r << 16) | (g << 8) | (b))
#define FROM_RGBA(r,g,b,a) ((r << 16) | (g << 8) | (b) | (a << 24))

struct Bitmap
{
	Uint32 *data;
	Uint32 width;
	Uint32 height;

	Bitmap(Uint32 Width, Uint32 Height);
	~Bitmap();

	void pset(Uint32 x, Uint32 y, Uint32 pixel);
	void pset(Uint32 x, Uint32 y, Uint8 R, Uint8 G, Uint8 B, Uint8 A = 255);
	Uint32 pget(Uint32 x, Uint32 y) const;

	void clear();
	bool saveToBMP(const char *fileName) const;

	void bltTo(Bitmap *target, Uint32 sx, Uint32 sy, Uint32 dx, Uint32 dy, Uint32 w, Uint32 h);
};


#endif /* BITMAP_H_ */
